#include "Timer.h"
#include "Event/EventDispatcher.h"

gee::Timer::Timer( gee::uint32 delay,gee::GeeSystem* sys /*= GeeSystem::getInstance()*/ ):delayTick(delay),m_sys(sys),running(false)
{

}
gee::Timer::~Timer()
{

}

void gee::Timer::tick()
{
	if(running)
	{
		TimerEvent* ev = new TimerEvent(gee::Timer::TIMER);
		ev->sender(this);
		m_sys->addEvent(this,ev);
		ev->decRef();
		m_sys->addWait(delayTick,this);
	}
}

void gee::Timer::start()
{
	running = true;
	if(m_sys)
	{
		this->incRef();
		m_sys->addWait(delayTick,this);
	}
}

void gee::Timer::stop()
{
	if(running)
	{
		running = false;
	}
}

gee::cchar* gee::Timer::TIMER = "gee_timer_tick";
